<template>
	<view class="main">
		<u-navbar
		    :title="$t('gaming.share')"
		    :autoBack="true"
			bgColor="#292929"
			leftIconColor="#FFFFFF"
			:titleStyle ="{color:'#FFFFFF',fontSize:'32rpx'}"
		 />
		<view class="my-link">
			<text class="link-title">{{$t('share.title')}}</text>
			<view class="link-code input-border">
				{{linkInfo.inviteLink}}
			</view>
			<button class="link-bth" @click="copyText">{{$t('share.bth')}}</button>
		</view>
		<view class="line" />
		<view class="link-list">
			<view class="link-item input-border" @click="linkList(1)" :class="listInfo.type==1?'checked':''">
				<view class="link-tips">
					{{linkInfo.directCount}}
				</view>
				<text class="link-text">{{$t('share.list1')}}</text>
			</view>
			<view class="link-item input-border" @click="linkList(2)" :class="listInfo.type==2?'checked':''">
				<view class="link-tips">
					{{linkInfo.indirectCount}}
				</view>
				<text class="link-text">{{$t('share.list2')}}</text>
			</view>
			<view class="link-item input-border"  @click="linkList(0)" :class="listInfo.type==0?'checked':''">
				<view class="link-tips">
					{{linkInfo.teamCount}}
				</view>
				<text class="link-text">{{$t('share.list3')}}</text>
			</view>
		</view>
		<view class="link-msg">
			<view class="msg-title">
				<text>ID:</text>
				<text>{{$t('share.tab1')}}</text>
				<text>{{$t('share.tab2')}}</text>
				<text>{{$t('share.tab3')}}</text>
			</view>
			<scroll-view scroll-y="true" class="scroll-y">
				<view class="msg-box input-border" v-for="item in linktable" :key="item.id">
					<text>ID:{{item.userId}}</text>
					<text  :class="item.state?'color-blue':'color-red'">{{item.state?'Active':'Free'}}</text>
					<text>{{item.rewardValue}}</text>
					<text>{{$u.timeFormat(item.createTime, 'yyyy/mm/dd')}}</text>
				</view>
			</scroll-view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				linkInfo:{},
				listInfo:{
				  type:1,
				  pageSize: 999,
				  pageNum: 1,
				  orderByColumn: "",
				  isAsc: ""
				},
				linkUrl:"",
				linktable:[]
			};
		},
		onShow() {
			this.getUser();
			this.linkList()
		},
		methods:{
			async getUser(){
				 const {data:res} = await this.$api('/front/getInviteData','GET')
				 this.linkInfo=res.data
				 this.linkUrl =JSON.parse(JSON.stringify(res.data.inviteLink)) 
				 const lengths = this.linkInfo.inviteLink.lastIndexOf("=")
				 this.linkInfo.inviteLink = this.linkInfo.inviteLink.substring(lengths + 1, this.linkInfo.inviteLink.length);
			},
			async linkList(item){
				if(item!=undefined)this.listInfo.type=item
				const {data:res} = await this.$api('/front/getInviteList','GET',this.listInfo)
				// console.log(res)
				this.linktable = res.rows
			},
			copyText(){
				uni.setClipboardData({
					   data:this.linkUrl,//要被复制的内容
					   success:()=>{
						 uni.showToast({
						   title:"copy success"
						 })
					   }
					});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100vw;
		min-height: 100vh;
		font-size: 20rpx;
		box-sizing: border-box;
		padding: 0 72rpx;
		padding-bottom: 40rpx;
		background: linear-gradient( 180deg, #000000 0%, #3C3C3C 100%);
		.my-link {
			width: 100%;
			display: flex;
			flex-direction: column;
            box-sizing: border-box;
			padding-top: 120rpx;
			.link-title {
				box-sizing: border-box;
				padding-left: 10rpx;
				color: #B2A5E0;
				font-size: 24rpx;
			}

			.link-code {
				height: 91rpx;
				border-radius: 17rpx;
				color: #fff;
				font-size: 24rpx;
				line-height: 91rpx;
				padding:0 30rpx;
				box-sizing: border-box;
				margin-top: 35rpx;
				overflow: hidden;
			}

			.link-bth {
				width: 100%;
				height: 90rpx;
				border-radius: 26rpx;
				background-color: #926FBF;
				color: #fff;
				font-size: 32rpx;
				margin-top: 43rpx;
			}
		}

		.line {
			height: 4rpx;
			width: 100%;
			background-color: #8D8A8F;
			margin-top: 82rpx;
		}

		.link-list {
			width: 100%;
			color: #B2A5E0;
			display: flex;
			justify-content: center;
			align-items: center;
			gap: 30rpx;
			margin-top: 82rpx;

			.link-item {
				width: 156rpx;
				height: 82rpx;
				text-align: center;
				border-radius: 18rpx;
				font-size: 22rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				position: relative;

				.link-tips {
					position: absolute;
					color: #B2A5E0;
					height: 40rpx;
					line-height: 36rpx;
					padding:0 12rpx;
					background-image: url('../../static/tips.png');
					background-size: 100% 100%;
					top: -20rpx;
					left: calc(100% - 20rpx);
				}
			}
			.checked{
				background-color: #B2A5E0;
				color: #fff;
			}
		}

		.link-msg {
			  width: 100%;
              color: #C6C6C6;
			  margin-top: 40rpx;
			.msg-title {
				width: 100%;
				height: 80rpx;
				padding-left: 30rpx;
				display: grid;
				grid-template-columns: 2fr 1fr 1fr 2fr;
				text-align: left;
			}
            .scroll-y{
				max-height: 600rpx;
				.msg-box {
					height: 91rpx;
					border-radius: 17rpx;
					color: #fff;
					font-size: 24rpx;
					line-height: 91rpx;
					padding-left: 30rpx;
					box-sizing: border-box;
					display: grid;
				    grid-template-columns: 2fr 1fr 1fr 2fr;
					text-align: left;
					margin-bottom: 10rpx;
					.color-blue{
						color: #54CCFF;
					}
					.color-red{
						color: red;
					}
				}
			}
			
		}
	}
</style>